<?php
/**
 * Created by PhpStorm.
 * User: zhan
 * Date: 2018/10/9  17:33
 */
namespace app\member\controller;

class Platform extends Common
{

    /*
    *	构造函数
    */
    function __construct()
    {
        parent::__construct();
    }

    public function lists()
    {
        $where = [];

        $where['am.id'] = $this->info['id'];

        $data = db('amount_log')->alias('al')->join('admin_member am','am.id=al.user_id')->where($where)->order('id desc')->field('al.*,am.account')->paginate(15)->each(function($item, $key){
            $item['createtime'] = date('Y-m-d H:i:s',$item['createtime']);
            $item['lid'] = json_decode($item['lid'],1);
            $item['lid'] = count($item['lid']);
            if(empty($item['each_price'])){
                $item['each_price'] = '0.00';
            }
            return $item;
        });

        $this->assign('list', $data);
        $this->assign('page', $data->render());
        return $this->fetch();
    }

    //充值凭证
    public function certificate_list()
    {
        $where = [];

        $where['uid'] = $this->info['id'];

        $check = input('check');

        if(!empty($check)){
            $where['check'] = $check;
        }

        $data = db('certificate')->where($where)->order('id desc')->paginate(15)->each(function($item, $key){
            $item['creatime'] = date('Y-m-d H:i:s',$item['creatime']);
            $item['image'] = IMG_PATH.$item['image'];
            return $item;
        });

        $this->assign('check',$check);
        $this->assign('list', $data);
        $this->assign('page', $data->render());
        return $this->fetch();
    }

    //添加凭证图片
    public function add_certificate()
    {
        if(request()->isAjax()){
            $data = [];
            $file = request()->file('file');
            if($file)
            {
                $info = $file->move(ROOT_PATH . 'public/static/uploads');
                if($info){
                    // 成功上传后 获取上传信息
                    $data['image'] =  $info->getSaveName();
                }else{
                    // 上传失败获取错误信息
                    $this->error($file->getError());
                }
            }
            $data['uid'] = $this->info['id'];
            $data['creatime'] = time();
            $re = db('certificate')->insert($data);
            if(!$re)$this->error('添加失败!');
            $this->success('添加成功！',url('Platform/certificate_list'));
        }
        return $this->fetch();
    }
}